package com.huawei.hwid.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import com.huawei.hwid.a.a.a;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.d.o;
import com.huawei.secure.android.common.intent.SafeIntent;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.lang.reflect.InvocationTargetException;

public class BridgeActivity extends Activity {
    private a a;

    private static void a(Window window, boolean z) {
        try {
            window.getClass().getMethod("setHwFloating", new Class[]{Boolean.TYPE}).invoke(window, new Object[]{Boolean.valueOf(z)});
        } catch (NoSuchMethodException e) {
            e.d("BridgeActivity", "In setHwFloating, NoSuchMethodException.", true);
        } catch (IllegalAccessException e2) {
            e.d("BridgeActivity", "In setHwFloating, IllegalAccessException.", true);
        } catch (IllegalArgumentException e3) {
            e.d("BridgeActivity", "In setHwFloating, IllegalArgumentException.", true);
        } catch (InvocationTargetException e4) {
            e.d("BridgeActivity", "In setHwFloating, InvocationTargetException.", true);
        }
    }

    public static Intent a(Context context, String str) {
        Intent intent = new Intent(context, BridgeActivity.class);
        intent.putExtra(com.huawei.hms.activity.BridgeActivity.EXTRA_DELEGATE_CLASS_NAME, str);
        intent.putExtra(com.huawei.hms.activity.BridgeActivity.EXTRA_IS_FULLSCREEN, false);
        return intent;
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        a();
        if (getIntent() != null) {
            if (!b()) {
                setResult(1, null);
                finish();
            }
            o.a((Activity) this);
        }
    }

    protected void onDestroy() {
        super.onDestroy();
        if (this.a != null) {
            this.a.a();
        }
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        if (this.a != null) {
            this.a.b();
        }
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        e.b("BridgeActivity", "onActivityResult,requestCode:" + i + ",resultCode:" + i2, true);
        super.onActivityResult(i, i2, intent);
        if (this.a != null && !this.a.a(i, i2, intent) && !isFinishing()) {
            setResult(i2, intent);
            finish();
        }
    }

    public boolean onKeyUp(int i, KeyEvent keyEvent) {
        if (this.a != null) {
            this.a.a(i, keyEvent);
        }
        return super.onKeyUp(i, keyEvent);
    }

    public void finish() {
        e.b("BridgeActivity", "Enter finish.", true);
        super.finish();
    }

    private void a() {
        requestWindowFeature(1);
        if (9 <= a.a) {
            Window window = getWindow();
            window.addFlags(HwAccountConstants.FLAG_TRANSLUCENT_STATUS);
            a(window, true);
        }
    }

    private boolean b() {
        Intent intent = getIntent();
        if (intent == null) {
            e.d("BridgeActivity", "In initialize, Must not pass in a null intent.", true);
            return false;
        }
        Intent intent2;
        if (intent instanceof SafeIntent) {
            intent2 = intent;
        } else {
            intent2 = new SafeIntent(intent);
            setIntent(intent2);
        }
        if (intent2.getBooleanExtra(com.huawei.hms.activity.BridgeActivity.EXTRA_IS_FULLSCREEN, false)) {
            getWindow().setFlags(WXMediaMessage.DESCRIPTION_LENGTH_LIMIT, WXMediaMessage.DESCRIPTION_LENGTH_LIMIT);
        }
        String stringExtra = intent2.getStringExtra(com.huawei.hms.activity.BridgeActivity.EXTRA_DELEGATE_CLASS_NAME);
        if (stringExtra == null) {
            e.d("BridgeActivity", "In initialize, Must not pass in a null or non class object.", true);
            return false;
        }
        try {
            this.a = (a) Class.forName(stringExtra).asSubclass(a.class).newInstance();
            this.a.a(this);
            return true;
        } catch (ClassCastException e) {
            e.d("BridgeActivity", "In initialize, Failed to create 'IUpdateWizard' instance.", true);
            return false;
        } catch (InstantiationException e2) {
            e.d("BridgeActivity", "In initialize, Failed to create 'InstantiationException' instance.", true);
            return false;
        } catch (IllegalAccessException e3) {
            e.d("BridgeActivity", "In initialize, Failed to create 'IllegalAccessException' instance.", true);
            return false;
        } catch (ClassNotFoundException e4) {
            e.d("BridgeActivity", "In initialize, Failed to create 'ClassNotFoundException' instance.", true);
            return false;
        }
    }
}
